<!DOCTYPE html>

<html lang="en-us">
<head>
  <title>Test Suite for sqlite.js</title>
  <script src="sqlite.js" type="text/javascript"></script>
</head>
<body>
<div id="results"></div>
<script type="text/javascript" charset="utf-8">

  function pass(results, query) {
    var target = document.getElementById('results'), html = target.innerHTML;
    target.innerHTML = html + 'pass - ' + query + '<br />';
  }

  function fail(error, query) {
    var target = document.getElementById('results'), html = target.innerHTML;
    target.innerHTML = html + 'fail - ' + error.message + ': ' + query + '<br />';
  }

  var db = SQLite({ shortName: 'mydb' + parseInt(Math.random() * 100000), defaultErrorHandler: fail, defaultDataHandler: pass });

  db.createTable('people', 'name TEXT, age INTEGER');

  db.insert('people', { name: "Jeremy", age: 29 });
  db.insert('people', { name: "Tara", age: 28 });

  db.update('people', { age: 30 }, { name: 'Jeremy' });

  db.select('people', '*', { age: 30 }, null, function (r, q) { pass(r, q); var x; for(x=0; x<r.rows.length; x++) { console.log(r.rows.item(x)); } });
  db.select('people', 'name', null, { order: 'age DESC' }, function (r, q) { pass(r, q); var x; for(x=0; x<r.rows.length; x++) { console.log(r.rows.item(x)); } });
  db.select('people', 'name', null, { limit: 1 }, function (r, q) { pass(r, q); var x; for(x=0; x<r.rows.length; x++) { console.log(r.rows.item(x)); } });

  db.destroy('people', { age: 30 });
</script>
</body>
</html>